<template>
    <el-form label-width="auto">
        <el-form-item label="生成时间">
            {{ createDate.toLocaleString() }}
        </el-form-item>
        <el-form-item label="订单号">
            {{ currentPartnerOrder?.orderCode }}
        </el-form-item>
        <el-form-item label="客户名称">
            {{ currentPartnerOrder?.customerName }}
        </el-form-item>
        <el-form-item label="客户电话">
            {{ currentPartnerOrder?.telephone }}
        </el-form-item>
        <el-form-item label="审单编码">
            {{ currentAudit?.auditCode }}
        </el-form-item>
        <el-form-item label="审单人">
            {{ currentAudit?.auditorName }}
        </el-form-item>
        <el-form-item label="审单历史">
            <ul>
                <li v-for="i in currentAudit?.auditOrderOperations">
                    {{ i.createTime }} {{ i.operator }} {{ i.roleName }}
                </li>
            </ul>
        </el-form-item>

        <el-form-item label="绘制信息">
            <ul>
                <li v-for="log in currentLogs">
                    <el-tag :type="log.level == 3 ? 'warning' : 'danger'">{{ log.level == 3 ? '警告' : '错误' }}</el-tag>
                    {{ log.message }}
                </li>
            </ul>
        </el-form-item>
    </el-form>
</template>

<script lang="ts">
import { defineComponent, ref, watch } from 'vue';
import { useCurrentModelStore } from '@/stores/current';
import type { KujialeAuditOrder } from '@/core3d/types/KujialeJsonModels/KujialeAuditOrder';
import type { KujialePartnerOrder } from '@/core3d/types/KujialeJsonModels/KujialePartnerOrder';
import { type LogItem, LogLevel } from '@/core3d/types/Log/LogItem';

export default defineComponent({
    setup(props, { emit, attrs }) {
        const createDate = ref<Date>(new Date());
        const currentAudit = ref<KujialeAuditOrder>();
        const currentPartnerOrder = ref<KujialePartnerOrder>();
        const currentLogs = ref<LogItem[]>([]);

        const store = useCurrentModelStore();
        watch(() => store.currentAuditOrder, (n, o) => {
            if (n) {
                currentAudit.value = n;
                currentAudit.value.auditOrderOperations.reverse();
            }
        });
        watch(() => store.currentPartnerOrder, (n, o) => {
            if (n) {
                currentPartnerOrder.value = n;
            }
        })
        watch(()=>store.currentCreateDate,(n,o)=>{
            if(n){
                createDate.value = n;
            }
        })

        watch(() => store.currentLogs, (n, o) => {
            if (n) {
                currentLogs.value = n.filter(i => i.level > 2);
            }
        })
        return { currentAudit, currentPartnerOrder, currentLogs, LogLevel, createDate };
    }
});
</script>